package com.smart.community.property.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Map;

/**
 * 维修工单统计视图对象
 * @author Wu.Liang
 * @since 2025-06-26
 * @version 1.0.0
 */
@Data
public class RepairOrderStatisticsVO {

    /** 社区ID */
    private Long communityId;

    /** 统计开始日期 */
    private LocalDate startDate;

    /** 统计结束日期 */
    private LocalDate endDate;

    /** 总工单数 */
    private Integer totalOrders;

    /** 待处理工单数 */
    private Integer pendingOrders;

    /** 处理中工单数 */
    private Integer processingOrders;

    /** 已完成工单数 */
    private Integer completedOrders;

    /** 已取消工单数 */
    private Integer cancelledOrders;

    /** 总处理时长（小时） */
    private BigDecimal totalProcessingTime;

    /** 平均处理时长（小时） */
    private BigDecimal averageProcessingTime;

    /** 按时完成率 */
    private BigDecimal onTimeCompletionRate;

    /** 用户满意度评分 */
    private BigDecimal satisfactionScore;

    /** 按类型统计 */
    private Map<String, Integer> ordersByType;

    /** 按优先级统计 */
    private Map<String, Integer> ordersByPriority;

    /** 按维修人员统计 */
    private Map<String, Integer> ordersByRepairman;

    /**
     * 计算完成率
     * @return 完成率
     */
    public BigDecimal getCompletionRate() {
        if (totalOrders == null || totalOrders == 0) {
            return BigDecimal.ZERO;
        }
        if (completedOrders == null) {
            return BigDecimal.ZERO;
        }
        return new BigDecimal(completedOrders)
                .divide(new BigDecimal(totalOrders), 4, BigDecimal.ROUND_HALF_UP)
                .multiply(new BigDecimal("100"));
    }

    /**
     * 计算处理率
     * @return 处理率
     */
    public BigDecimal getProcessingRate() {
        if (totalOrders == null || totalOrders == 0) {
            return BigDecimal.ZERO;
        }
        int processingCount = (processingOrders != null ? processingOrders : 0) + 
                             (completedOrders != null ? completedOrders : 0);
        return new BigDecimal(processingCount)
                .divide(new BigDecimal(totalOrders), 4, BigDecimal.ROUND_HALF_UP)
                .multiply(new BigDecimal("100"));
    }
}
